function [vardecomp]=SIGEvardec(pars)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This is part of the set of files that accompany the article:       %
%Mankiw, N. Gregory and Ricardo Reis (2007) "Sticky Information in  %
%General Equilibrium," Journal of the European Economic Association,%
%forthcoming. See the appendix of the NBER or CEPR working paper    %
%versions for a detailed explanation of the algorithms.             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Please cite if you use the programs. I do not provide tech support.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Last revised: August 30, 2006                                      %
%Written by: Ricardo Reis                                           %
%Input: Full list of parameters                                     %
%Output: Variance decomposition                                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%STEP 1: RECOVER PARAMETERS %%%%%
sigma_m=pars(9); sigma_a=pars(11); sigma_g=pars(13); sigma_nu=pars(15);
sigma_gam=pars(17);

%%%%STEP 2: SOLVE FOR MA REPRESENTATION %%%%%
[ma_m ma_a ma_g ma_nu ma_gam]=SIGEmafive(pars);

%%%%STEP 3: VARIANCE DECOMPOSITION %%%%%
%inflation%
temp=(sigma_m^2)*(ma_m(:,1)'*ma_m(:,1))+(sigma_a^2)*(ma_a(:,1)'*ma_a(:,1))+(sigma_g^2)*(ma_g(:,1)'*ma_g(:,1))+(sigma_nu^2)*(ma_nu(:,1)'*ma_nu(:,1))+(sigma_gam^2)*(ma_gam(:,1)'*ma_gam(:,1));
vardecomp(1,1)=((sigma_m^2)*(ma_m(:,1)'*ma_m(:,1)))/temp;
vardecomp(1,2)=((sigma_a^2)*(ma_a(:,1)'*ma_a(:,1)))/temp;
vardecomp(1,3)=((sigma_g^2)*(ma_g(:,1)'*ma_g(:,1)))/temp;
vardecomp(1,4)=((sigma_nu^2)*(ma_nu(:,1)'*ma_nu(:,1)))/temp;
vardecomp(1,5)=((sigma_gam^2)*(ma_gam(:,1)'*ma_gam(:,1)))/temp;
clear temp;
% Dy %
temp=(sigma_m^2)*(ma_m(:,2)'*ma_m(:,2))+(sigma_a^2)*(ma_a(:,2)'*ma_a(:,2))+(sigma_g^2)*(ma_g(:,2)'*ma_g(:,2))+(sigma_nu^2)*(ma_nu(:,2)'*ma_nu(:,2))+(sigma_gam^2)*(ma_gam(:,2)'*ma_gam(:,2));
vardecomp(2,1)=((sigma_m^2)*(ma_m(:,2)'*ma_m(:,2)))/temp;
vardecomp(2,2)=((sigma_a^2)*(ma_a(:,2)'*ma_a(:,2)))/temp;
vardecomp(2,3)=((sigma_g^2)*(ma_g(:,2)'*ma_g(:,2)))/temp;
vardecomp(2,4)=((sigma_nu^2)*(ma_nu(:,2)'*ma_nu(:,2)))/temp;
vardecomp(2,5)=((sigma_gam^2)*(ma_gam(:,2)'*ma_gam(:,2)))/temp;
clear temp;
%i%
temp=(sigma_m^2)*(ma_m(:,3)'*ma_m(:,3))+(sigma_a^2)*(ma_a(:,3)'*ma_a(:,3))+(sigma_g^2)*(ma_g(:,3)'*ma_g(:,3))+(sigma_nu^2)*(ma_nu(:,3)'*ma_nu(:,3))+(sigma_gam^2)*(ma_gam(:,3)'*ma_gam(:,3));
vardecomp(3,1)=((sigma_m^2)*(ma_m(:,3)'*ma_m(:,3)))/temp;
vardecomp(3,2)=((sigma_a^2)*(ma_a(:,3)'*ma_a(:,3)))/temp;
vardecomp(3,3)=((sigma_g^2)*(ma_g(:,3)'*ma_g(:,3)))/temp;
vardecomp(3,4)=((sigma_nu^2)*(ma_nu(:,3)'*ma_nu(:,3)))/temp;
vardecomp(3,5)=((sigma_gam^2)*(ma_gam(:,3)'*ma_gam(:,3)))/temp;
clear temp;
% Dwp %
temp=(sigma_m^2)*(ma_m(:,4)'*ma_m(:,4))+(sigma_a^2)*(ma_a(:,4)'*ma_a(:,4))+(sigma_g^2)*(ma_g(:,4)'*ma_g(:,4))+(sigma_nu^2)*(ma_nu(:,4)'*ma_nu(:,4))+(sigma_gam^2)*(ma_gam(:,4)'*ma_gam(:,4));
vardecomp(4,1)=((sigma_m^2)*(ma_m(:,4)'*ma_m(:,4)))/temp;
vardecomp(4,2)=((sigma_a^2)*(ma_a(:,4)'*ma_a(:,4)))/temp;
vardecomp(4,3)=((sigma_g^2)*(ma_g(:,4)'*ma_g(:,4)))/temp;
vardecomp(4,4)=((sigma_nu^2)*(ma_nu(:,4)'*ma_nu(:,4)))/temp;
vardecomp(4,5)=((sigma_gam^2)*(ma_gam(:,4)'*ma_gam(:,4)))/temp;
clear temp;
% hours %
temp=(sigma_m^2)*(ma_m(:,5)'*ma_m(:,5))+(sigma_a^2)*(ma_a(:,5)'*ma_a(:,5))+(sigma_g^2)*(ma_g(:,5)'*ma_g(:,5))+(sigma_nu^2)*(ma_nu(:,5)'*ma_nu(:,5))+(sigma_gam^2)*(ma_gam(:,5)'*ma_gam(:,5));
vardecomp(5,1)=((sigma_m^2)*(ma_m(:,5)'*ma_m(:,5)))/temp;
vardecomp(5,2)=((sigma_a^2)*(ma_a(:,5)'*ma_a(:,5)))/temp;
vardecomp(5,3)=((sigma_g^2)*(ma_g(:,5)'*ma_g(:,5)))/temp;
vardecomp(5,4)=((sigma_nu^2)*(ma_nu(:,5)'*ma_nu(:,5)))/temp;
vardecomp(5,5)=((sigma_gam^2)*(ma_gam(:,5)'*ma_gam(:,5)))/temp;
clear temp;